package com.ruoyi.fee.service.impl;

import com.ruoyi.fee.mapper.PropertyPaymentMapper;
import com.ruoyi.fee.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements IReportService {
    @Autowired
    private PropertyPaymentMapper paymentMapper;

    // 按月份统计缴费金额
    @Override
    public List<Map<String, Object>> getMonthlyPayment(String year) {
        List<Map<String, Object>> data = paymentMapper.selectMonthlyPayment(year);
        // 补全12个月数据
        for (int i = 1; i <= 12; i++) {
            String month = String.format("%02d", i);
            boolean exists = data.stream().anyMatch(m -> month.equals(m.get("month")));
            if (!exists) {
                Map<String, Object> item = new HashMap<>();
                item.put("month", month);
                item.put("amount", 0);
                data.add(item);
            }
        }
        // 按月份排序
        data.sort(Comparator.comparing(m -> m.get("month").toString()));
        return data;
    }
}